package org.light.jpa.core;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.light.core.Writeable;
import org.light.domain.IndependentConfig;
import org.light.domain.Statement;
import org.light.utils.StringUtil;
import org.light.utils.WriteableUtil;

public class JPAPOMXml extends IndependentConfig{	
	private static final long serialVersionUID = 1881392732324115362L;
	protected String projectName;
	protected String dbType = "mariadb";
	protected Set<String> moduleNames = new TreeSet<>();
	public JPAPOMXml(){
		super();		
		this.standardName = "Boot3PomXml";
		this.fileName = "pom.xml";
	}
	
	public JPAPOMXml(String dbType){
		this();
		this.dbType = dbType;
	}
	
	@Override
	public String generateImplString() {
    	List<Writeable> sList = new ArrayList<Writeable>();
    	sList.add(new Statement(1000L,0,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
    	sList.add(new Statement(2000L,0,"<project xmlns=\"http://maven.apache.org/POM/4.0.0\""));
    	sList.add(new Statement(3000L,0,"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""));
    	sList.add(new Statement(4000L,0,"xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">"));
    	sList.add(new Statement(5000L,1,"<packaging>jar</packaging>"));
    	sList.add(new Statement(6000L,1,"<modelVersion>4.0.0</modelVersion>"));
    	sList.add(new Statement(7000L,0,""));
    	sList.add(new Statement(8000L,1,"<groupId>org.javaforever</groupId>"));
    	sList.add(new Statement(9000L,1,"<artifactId>"+this.projectName+"</artifactId>"));
    	sList.add(new Statement(10000L,1,"<version>1.0-SNAPSHOT</version>"));
    	sList.add(new Statement(11000L,0,""));
    	sList.add(new Statement(12000L,1,"<parent>"));
    	sList.add(new Statement(13000L,2,"<groupId>org.springframework.boot</groupId>"));
    	sList.add(new Statement(14000L,2,"<artifactId>spring-boot-starter-parent</artifactId>"));
    	sList.add(new Statement(15000L,2,"<version>3.4.0</version>"));
    	sList.add(new Statement(16000L,2,"<relativePath />"));
    	sList.add(new Statement(17000L,1,"</parent>"));
    	sList.add(new Statement(18000L,0,""));
    	sList.add(new Statement(19000L,0,"<dependencies>"));
    	
    	sList.add(new Statement(20000L,1,"<dependency>"));
    	sList.add(new Statement(20100L,2,"<groupId>com.alibaba</groupId>"));
    	sList.add(new Statement(20200L,2,"<artifactId>fastjson</artifactId>"));
    	sList.add(new Statement(20300L,2,"<version>1.2.58</version>"));
    	sList.add(new Statement(20400L,2,"<scope>compile</scope>"));
    	sList.add(new Statement(20500L,1,"</dependency>"));

    	sList.add(new Statement(21000L,1,"<dependency>"));
    	sList.add(new Statement(21500L,2,"<groupId>org.apache.commons</groupId>"));
    	sList.add(new Statement(22000L,2,"<artifactId>commons-lang3</artifactId>"));
    	sList.add(new Statement(23000L,2,"<version>3.0</version>"));
    	sList.add(new Statement(24000L,1,"</dependency>"));
    	sList.add(new Statement(25000L,1,"<dependency>"));
    	sList.add(new Statement(26000L,2,"<groupId>commons-io</groupId>"));
    	sList.add(new Statement(27000L,2,"<artifactId>commons-io</artifactId>"));
    	sList.add(new Statement(28000L,2,"<version>2.18.0</version>"));
    	sList.add(new Statement(29000L,1,"</dependency>"));
    	sList.add(new Statement(30000L,1,"<dependency>"));
    	sList.add(new Statement(31000L,2,"<groupId>org.apache.poi</groupId>"));
    	sList.add(new Statement(32000L,2,"<artifactId>poi</artifactId>"));
    	sList.add(new Statement(33000L,2,"<version>5.3.0</version>"));
    	sList.add(new Statement(34000L,1,"</dependency>"));
    	
    	sList.add(new Statement(35000L,1,"<dependency>"));    	
    	sList.add(new Statement(36000L,2,"<groupId>org.apache.xmlgraphics</groupId>"));
    	sList.add(new Statement(37000L,2,"<artifactId>batik-anim</artifactId>"));
    	sList.add(new Statement(38000L,2,"<version>1.11</version>"));
    	sList.add(new Statement(39000L,1,"</dependency>"));
    	sList.add(new Statement(40000L,1,"<dependency>"));
    	sList.add(new Statement(41000L,2,"<groupId>org.apache.poi</groupId>"));
    	sList.add(new Statement(42000L,2,"<artifactId>poi-ooxml</artifactId>"));
    	sList.add(new Statement(43000L,2,"<version>5.3.0</version>"));
    	sList.add(new Statement(44000L,1,"</dependency>"));
    	
    	sList.add(new Statement(45000L,1,"<dependency>"));
    	sList.add(new Statement(46000L,2,"<groupId>org.springframework.boot</groupId>"));
    	sList.add(new Statement(47000L,2,"<artifactId>spring-boot-starter-web</artifactId>"));
    	sList.add(new Statement(48000L,2,"<exclusions>"));
    	sList.add(new Statement(49000L,3,"<exclusion>"));
    	sList.add(new Statement(49500L,4,"<groupId>org.springframework.boot</groupId>"));
    	sList.add(new Statement(49600L,4,"<artifactId>spring-boot-starter-tomcat</artifactId>"));
    	sList.add(new Statement(49700L,3,"</exclusion>"));
    	sList.add(new Statement(49800L,2,"</exclusions>"));
    	sList.add(new Statement(49900L,1,"</dependency>"));
//    	sList.add(new Statement(45000L,0,"<dependency>"));
//    	sList.add(new Statement(46000L,1,"<groupId>javax.servlet</groupId>"));
//    	sList.add(new Statement(47000L,1,"<artifactId>javax.servlet-api</artifactId>"));
//    	sList.add(new Statement(48000L,1,"<version>3.1.0</version>"));
//    	sList.add(new Statement(49000L,0,"</dependency>"));
    	sList.add(new Statement(50000L,1,"<dependency>"));
    	sList.add(new Statement(51000L,2,"<groupId>org.springframework.boot</groupId>"));
    	sList.add(new Statement(52000L,2,"<artifactId>spring-boot-starter-tomcat</artifactId>"));
    	sList.add(new Statement(53000L,2,"<scope>provided</scope>"));
    	sList.add(new Statement(54000L,1,"</dependency>"));
    	sList.add(new Statement(55000L,1,"<dependency>"));
    	sList.add(new Statement(56000L,2,"<groupId>org.springframework.boot</groupId>"));
    	sList.add(new Statement(57000L,2,"<artifactId>spring-boot-starter-data-jpa</artifactId>"));
    	sList.add(new Statement(59000L,1,"</dependency>"));
    	
    	if (this.moduleNames.contains("ShiroAuth")) {
    		sList.add(new Statement(59010L,1,"<dependency>"));
    		sList.add(new Statement(59020L,2,"<groupId>org.apache.shiro</groupId>"));
    		sList.add(new Statement(59030L,2,"<artifactId>shiro-spring</artifactId>"));
    		sList.add(new Statement(59040L,2,"<version>1.13.0</version>"));
    		sList.add(new Statement(59050L,2,"<exclusions>"));
    		sList.add(new Statement(59060L,3,"<exclusion>"));
    		sList.add(new Statement(59070L,4,"<groupId>org.apache.shiro</groupId>"));
    		sList.add(new Statement(59080L,4,"<artifactId>shiro-web</artifactId>"));
    		sList.add(new Statement(59090L,3,"</exclusion>"));
    		sList.add(new Statement(59100L,3,"<exclusion>"));
    		sList.add(new Statement(59110L,4,"<groupId>org.apache.shiro</groupId>"));
    		sList.add(new Statement(59120L,4,"<artifactId>shiro-core</artifactId>"));
    		sList.add(new Statement(59130L,3,"</exclusion>"));
    		sList.add(new Statement(59140L,2,"</exclusions>"));
    		sList.add(new Statement(59150L,2,"<classifier>jakarta</classifier>"));
    		sList.add(new Statement(59160L,1,"</dependency>"));
    		sList.add(new Statement(59170L,1,"<dependency>"));
    		sList.add(new Statement(59180L,2,"<groupId>org.apache.shiro</groupId>"));
    		sList.add(new Statement(59190L,2,"<artifactId>shiro-core</artifactId>"));
    		sList.add(new Statement(59200L,2,"<version>1.13.0</version>"));
    		sList.add(new Statement(59210L,2,"<classifier>jakarta</classifier>"));
    		sList.add(new Statement(59220L,1,"</dependency>"));
    		sList.add(new Statement(59230L,1,"<dependency>"));
    		sList.add(new Statement(59240L,2,"<groupId>org.apache.shiro</groupId>"));
    		sList.add(new Statement(59250L,2,"<artifactId>shiro-web</artifactId>"));
    		sList.add(new Statement(59260L,2,"<version>1.13.0</version>"));
    		sList.add(new Statement(59270L,2,"<classifier>jakarta</classifier>"));
    		sList.add(new Statement(59280L,1,"</dependency>"));
    		sList.add(new Statement(59290L,1,"<dependency>"));
    		sList.add(new Statement(59300L,2,"<groupId>javax.xml.bind</groupId>"));
    		sList.add(new Statement(59310L,2,"<artifactId>jaxb-api</artifactId>"));
    		sList.add(new Statement(59320L,2,"<version>2.3.0</version>"));
    		sList.add(new Statement(59330L,1,"</dependency>"));
    		
    		sList.add(new Statement(59880L,1,"<dependency>"));
    		sList.add(new Statement(59890L,2,"<groupId>com.github.theborakompanioni</groupId>"));
    		sList.add(new Statement(59900L,2,"<artifactId>thymeleaf-extras-shiro</artifactId>"));
    		sList.add(new Statement(59911L,2,"<version>2.0.0</version>"));
    		sList.add(new Statement(59912L,1,"</dependency>"));
    		sList.add(new Statement(59913L,2,""));
    		sList.add(new Statement(59915L,1,"<dependency>"));
    		sList.add(new Statement(59916L,2,"<groupId>org.springframework.boot</groupId>"));
    		sList.add(new Statement(59917L,2,"<artifactId>spring-boot-starter-thymeleaf</artifactId>"));
    		sList.add(new Statement(59918L,2,"<version>2.1.1.RELEASE</version>"));
    		sList.add(new Statement(59919L,1,"</dependency>"));
		}
    	
    	if (StringUtil.isBlank(this.dbType)||"mariadb".equalsIgnoreCase(this.dbType)) {
	    	sList.add(new Statement(60000L,1,"<dependency>"));
	    	sList.add(new Statement(61000L,2,"<groupId>org.mariadb.jdbc</groupId>"));
	    	sList.add(new Statement(62000L,2,"<artifactId>mariadb-java-client</artifactId>"));
	    	sList.add(new Statement(62500L,2,"<version>3.5.1</version>"));
	    	sList.add(new Statement(63000L,1,"</dependency>"));
    	} else if ("mysql".equalsIgnoreCase(this.dbType)) {
	    	sList.add(new Statement(60000L,1,"<dependency>"));
	    	sList.add(new Statement(61000L,2,"<groupId>mysql</groupId>"));
	    	sList.add(new Statement(62000L,2,"<artifactId>mysql-connector-java</artifactId> "));
	    	sList.add(new Statement(63000L,2,"<version>8.0.17</version>"));
	    	sList.add(new Statement(63500L,1,"</dependency>"));
    	} else if ("oracle".equalsIgnoreCase(this.dbType)){
//	    	sList.add(new Statement(60000L,0,"<dependency>"));
//	    	sList.add(new Statement(61000L,1,"<groupId>com.oracle.jdbc</groupId>"));
//	    	sList.add(new Statement(61500L,1,"<artifactId>ojdbc6</artifactId>"));
//	    	sList.add(new Statement(62000L,1,"<version>11.2.0.4</version>"));
//	    	sList.add(new Statement(62100L,1,"<scope>system</scope>"));
//	    	sList.add(new Statement(62200L,1,"<systemPath>${basedir}/src/main/webapp/WEB-INF/lib/ojdbc6.jar</systemPath>"));
//	    	sList.add(new Statement(63000L,0,"</dependency>"));
    		sList.add(new Statement(60000L,1,"<dependency>"));
    		sList.add(new Statement(61100L,2,"<groupId>com.oracle.database.jdbc</groupId>"));
    		sList.add(new Statement(61200L,2,"<artifactId>ojdbc8</artifactId>"));
    		sList.add(new Statement(61300L,2,"<version>19.6.0.0</version>"));
    		sList.add(new Statement(61400L,1,"</dependency>"));
    		sList.add(new Statement(61500L,0,""));
    		sList.add(new Statement(61600L,1,"<!-- https://mvnrepository.com/artifact/cn.easyproject/orai18n -->"));
    		sList.add(new Statement(61700L,1,"<dependency>"));
    		sList.add(new Statement(61800L,2,"<groupId>cn.easyproject</groupId>"));
    		sList.add(new Statement(61900L,2,"<artifactId>orai18n</artifactId>"));
    		sList.add(new Statement(62000L,2,"<version>12.1.0.2.0</version>"));
    		sList.add(new Statement(62100L,1,"</dependency>"));

    	}
    	else if ("postgresql".equalsIgnoreCase(this.dbType)||"pgsql".equalsIgnoreCase(this.dbType)){
	    	sList.add(new Statement(60000L,1,"<dependency>"));
	    	sList.add(new Statement(61000L,2,"<groupId>org.postgresql</groupId>"));
	    	sList.add(new Statement(62000L,2,"<artifactId>postgresql</artifactId>"));
	    	sList.add(new Statement(62100L,2,"<version>42.2.5</version>"));
	    	sList.add(new Statement(63000L,1,"</dependency>"));
    	}
    	sList.add(new Statement(64000L,1,"<dependency>"));
    	sList.add(new Statement(65000L,2,"<groupId>com.itextpdf</groupId>"));
    	sList.add(new Statement(66000L,2,"<artifactId>itext-asian</artifactId>"));
    	sList.add(new Statement(67000L,2,"<version>5.2.0</version>"));
    	sList.add(new Statement(68000L,1,"</dependency>"));
    	sList.add(new Statement(69000L,1,"<dependency>"));
    	sList.add(new Statement(70000L,2,"<groupId>com.itextpdf</groupId>"));
    	sList.add(new Statement(71000L,2,"<artifactId>itextpdf</artifactId>"));
    	sList.add(new Statement(72000L,2,"<version>5.4.3</version>"));
    	sList.add(new Statement(73000L,1,"</dependency>"));
    	
    	sList.add(new Statement(74000L,1,"<dependency>"));
    	sList.add(new Statement(75000L,2,"<groupId>com.lowagie</groupId>"));
    	sList.add(new Statement(76000L,2,"<artifactId>itext</artifactId>"));
    	sList.add(new Statement(77000L,2,"<version>2.1.7</version>"));
    	sList.add(new Statement(78000L,1,"</dependency>"));
    	sList.add(new Statement(79000L,1,"<dependency>"));
    	sList.add(new Statement(80000L,2,"<groupId>com.lowagie</groupId>"));
    	sList.add(new Statement(81000L,2,"<artifactId>itext-rtf</artifactId>"));
    	sList.add(new Statement(82000L,2,"<version>2.1.7</version>"));
    	sList.add(new Statement(83000L,1,"</dependency>"));
    	
		sList.add(new Statement(84000L,0,"</dependencies>"));
		
		sList.add(new Statement(85000L,0,"<build>"));
		sList.add(new Statement(86000L,0,"<plugins>"));
		sList.add(new Statement(87000L,0,"<plugin>"));
		sList.add(new Statement(88000L,1,"<groupId>org.springframework.boot</groupId>"));
		sList.add(new Statement(89000L,1,"<artifactId>spring-boot-maven-plugin</artifactId>"));
		sList.add(new Statement(90000L,1,"<version>3.4.0</version>"));
		sList.add(new Statement(91000L,1,"<configuration>"));
		sList.add(new Statement(92000L,1,"<fork>true</fork>"));
		sList.add(new Statement(93000L,1,"</configuration>"));
		sList.add(new Statement(94000L,1,"</plugin>"));
		sList.add(new Statement(95000L,0,"</plugins>"));
		sList.add(new Statement(96000L,0,"</build>"));
		
    	sList.add(new Statement(97000L,0,"</project>"));
    	return WriteableUtil.merge(sList).getContent();
	}

	public String getProjectName() {
		return projectName;
	}

	public void setProjectName(String projectName) {
		this.projectName = projectName;
	}

	public String getDbType() {
		return dbType;
	}

	public void setDbType(String dbType) {
		this.dbType = dbType;
	}

	public Set<String> getModuleNames() {
		return moduleNames;
	}

	public void setModuleNames(Set<String> moduleNames) {
		this.moduleNames = moduleNames;
	}

}
